package com.colin.juc.lock.reentrantlock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by Colin on 2020/4/7 21:17
 * email: colinzhaodong@gmail.com
 * desc:  使用可重入锁演示预定电影院座位
 *
 * @author zhaod
 */
public class CinemaBookSeat {
	private static ReentrantLock lock = new ReentrantLock();
	private static void bookSeat() {
		lock.lock();
		try {
			System.out.println(Thread.currentThread().getName() + "开始预定座位");
			Thread.sleep(1000);
			System.out.println(Thread.currentThread().getName() + "完成预定座位");
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			lock.unlock();
		}
	}

	public static void main(String[] args) {
		new Thread(CinemaBookSeat::bookSeat).start();
		new Thread(CinemaBookSeat::bookSeat).start();
		new Thread(CinemaBookSeat::bookSeat).start();
		new Thread(CinemaBookSeat::bookSeat).start();
	}
}
